﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.peddlerUI {
    import flash.events.*;
    import flash.display.*;
    import flash.geom.*;
    import flash.utils.*;
    import Display.DialogUI.*;
    import Classes.*;
    import Classes.util.*;
    import com.greensock.*;
    import Display.hud.components.*;
    import Modules.peddler.*;
    import Display.peddlerUI.peddlerMarketUI.data.*;
    import Display.aswingui.*;
    import com.greensock.easing.*;

    public class PeddlerBar extends GenericDialog {

        private static var OFFSET_STAGE:Number = 10;
        private static var m_instance:PeddlerBar;

        private var m_ishiding:Boolean = true;
        private var m_peddlersData:Array;

        public function PeddlerBar(_arg1:Function=null){
            super("", "", 0, _arg1, "", "", false);
        }
        public static function getInstance():PeddlerBar{
            if (!m_instance){
                m_instance = new (PeddlerBar)();
            };
            return (m_instance);
        }

        override protected function init():void{
            super.init();
            this.visible = false;
            this.x = this.getOffstageX();
            this.y = this.getStageY();
        }
        protected function getOnstageX():Number{
            return (75);
        }
        protected function getOffstageX():Number{
            var _local1:Number = -(this.m_jwindow.width);
            return (_local1);
        }
        protected function getStageY():Number{
            var _local2:HUDComponent;
            var _local1:HUDComponentContainer = (Global.hud.getComponent("visitStack") as HUDComponentContainer);
            if (_local1){
                _local2 = _local1.getComponent(HUDPeddlerComponent);
                if (_local2){
                    return ((_local1.y + _local2.y));
                };
                return (_local1.y);
            };
            return (10);
        }
        override protected function getAssetDependencies():Array{
            return ([DelayedAssetLoader.INVENTORY_ASSETS]);
        }
        override protected function onAssetsLoaded(_arg1:Event=null):void{
            var _local2:Dictionary = new Dictionary();
            _local2["dialog_bg"] = (new EmbeddedArt.Peddler_bg() as DisplayObject);
            m_jpanel = this.createDialogView(_local2);
            finalizeAndShow();
            ASwingHelper.prepare(m_jpanel);
            ASwingHelper.prepare(m_jwindow);
            this.buttonMode = true;
            this.mouseChildren = false;
            Global.hud.addChild(this);
            Global.stage.addEventListener(FullScreenEvent.FULL_SCREEN, onFullScreen);
            this.createEventListener();
        }
        override protected function createDialogView(_arg1:Dictionary):GenericDialogView{
            var _local2:PeddlerBarView = new PeddlerBarView(_arg1, m_message, m_title, m_type, m_callback);
            return (_local2);
        }
        protected function createEventListener():Boolean{
            this.m_jwindow.addEventListener(MouseEvent.ROLL_OUT, this.onMouseOut);
            return (true);
        }
        protected function onMouseOut(_arg1:MouseEvent):void{
        }
        override protected function hideTween(_arg1:Function):void{
            this.mouseEnabled = (this.mouseChildren = false);
            _arg1();
            Sounds.play("dialogClose");
        }
        override protected function showTween():void{
            this.mouseEnabled = (this.mouseChildren = false);
            var _local1:Point = new Point(m_content.width, m_content.height);
            var _local2:Matrix = new Matrix();
            _local2.translate((-(_local1.x) / 2), (-(_local1.y) / 2));
            _local2.scale(1, 1);
            _local2.translate((_local1.x / 2), (_local1.y / 2));
            m_content.transform.matrix = _local2;
            onShowComplete();
        }
        public function startAnim():void{
            this.x = this.getOffstageX();
            this.y = this.getStageY();
            show();
            TweenLite.to(this, 0.6, {
                x:this.getOnstageX(),
                ease:Back.easeOut,
                onComplete:function ():void{
                    m_ishiding = false;
                }
            });
        }
        public function setSelectorData(_arg1:Array):void{
            this.m_peddlersData = _arg1;
            if (this.m_peddlersData){
                (m_jpanel as PeddlerBarView).setUpDataForDialog(this.m_peddlersData);
            };
        }
        public function setUpDataForBar():void{
            if (true == m_shown){
                this.closePeddler();
            } else {
                if (((this.m_peddlersData) && ((this.m_peddlersData.length > 0)))){
                    this.startAnim();
                };
            };
        }
        public function upDateCell(_arg1:PeddlerModel):void{
            (this.m_jpanel as PeddlerBarView).updateCell(_arg1);
        }
        public function closePeddler():void{
            if (this.m_ishiding == false){
                this.m_ishiding = true;
                TweenLite.to(this, 0.4, {
                    x:this.getOffstageX(),
                    ease:Back.easeIn,
                    onComplete:function ():void{
                        hide();
                    }
                });
            };
        }
        public function getAvailableCell():PeddlerCell{
            var _local1:PeddlerCell;
            var _local3:PeddlerData;
            var _local2:int;
            while (_local2 < this.m_peddlersData.length) {
                _local3 = this.m_peddlersData[_local2];
                if (_local3.status == PeddlerModel.STATE_FREE){
                    _local1 = ((m_jpanel as PeddlerBarView).getCell(_local2) as PeddlerCell);
                    break;
                };
                _local2++;
            };
            if (null == _local1){
                _local1 = ((m_jpanel as PeddlerBarView).getCell(0) as PeddlerCell);
            };
            return (_local1);
        }

    }
}//package Display.peddlerUI 
